L2-037 包装机

题目 L2-037 包装机

image-0904f691

思路分析

代码实现

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

using ll = long long;

using ull = unsigned long long;

using PII = pair<int, int>;

using Pll = pair<ll, ll>;

int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };

const int inf = 0x3f3f3f3f;

int n,m,S;

vector<queue<char>> q;

stack<char> stk;

signed main() {

    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin>>n>>m>>S;

	q.resize(n+1);

	for(int i=1;i<=n;i++){

		string s;cin>>s;

		for(int j=0;j<m;j++)	q[i].push(s[j]);

	}

	while(true){

		int op;cin>>op;

		if(op==-1)	break;

		if(op==0){

			if(!stk.empty()){

				cout<<stk.top();

				stk.pop();

			}

		}else{

			if(!q[op].empty()){

				if(stk.size()==S){

					cout<<stk.top();

					stk.pop();

				}

				stk.push(q[op].front());

				q[op].pop();

			}

		}

	}

    return 0;

}

同类题型

视频讲解


⬅️ L2-036 网红点打卡攻略 🏠 00-天梯赛 ➡️ L2-038 病毒溯源